package artibella.media 
{
	import artibella.IDisposable;
	import artibella.media.controls.AController;
	import artibella.media.events.MediaEvent;
	
	import flash.events.EventDispatcher;
	import flash.media.SoundTransform;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class AMedia extends EventDispatcher implements IDisposable
	{
		protected var _url:String;
		protected var _controller:AController;
		
		protected var _vol:Number = 0;
		protected var _position:Number = 0; //-1;
		protected var _duration:Number; // 
		
		protected var _reglageAudio:SoundTransform;
		
		public function AMedia() 
		{
			_init();
		}
		
		protected function _init():void 
		{
			// override this
		}
		
		// - - -
		
		public function play():void
		{
			SoundManager.instance.playSound( this );
			
			dispatchEvent( new MediaEvent( MediaEvent.PLAY ) );
		}
		
		public function pause():void
		{
			dispatchEvent( new MediaEvent( MediaEvent.PAUSE ) );
		}
		
		public function stop():void
		{
			//SoundManager.instance.stopSound( this );
			
			dispatchEvent( new MediaEvent( MediaEvent.STOP ) );
		}
		
		public function seek( p:Number, paused:Boolean = false ):void
		{
			dispatchEvent( new MediaEvent( MediaEvent.SEEK, _position.toString() ) );
		}
		
		// - - -
		
		public function get volume():Number
		{
			return _vol;
		}
		
		public function set volume( v:Number ):void
		{
			_vol = v;
		}
		
		public function get position():Number
		{
			return _position;
		}
		
		public function get duration():Number
		{
			return -1;
		}

		//----- IDisposable
		
		public function dispose():void
		{
			_controller = null;
			
			_url = null;
		}
		
		// - - - ID
		
		public function get url():String
		{
			return _url;
		}
	}
}